package com.company.huisuo.repository

import com.company.huisuo.biz.bean.GamePlanBean
import com.company.huisuo.biz.bean.GamePlanResponse
import com.company.huisuo.network.RetrofitClient
import com.company.huisuo.network.api.GamePlanApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * 游戏剧本数据仓库
 */
class GamePlanRepository {
    
    private val gamePlanApi: GamePlanApi by lazy {
        RetrofitClient.createService()
    }
    
    /**
     * 获取游戏剧本列表
     * @param gameType 游戏类型参数
     */
    suspend fun getGamePlanList(gameType: String? = null): Result<List<GamePlanBean>> = withContext(Dispatchers.IO) {
        try {
            val response = gamePlanApi.getAvailableByType(gameType)
            if (response.code == 0 && response.data != null) {
                Result.success(response.data)
            } else {
                Result.failure(Exception(response.msg ?: "获取游戏剧本列表失败"))
            }
        } catch (e: Exception) {
            Result.failure(Exception("网络请求失败: ${e.message}"))
        }
    }
}